package com.atguigu.jxc.service.impl;/*
 *@author 尹凯瑞
 *@date 2020/12/5 11:32
 */

import com.atguigu.jxc.dao.OverflowDao;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.OverflowList;
import com.atguigu.jxc.entity.OverflowListGoods;
import com.atguigu.jxc.service.OverflowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OverflowServiceImpl implements OverflowService {

    @Autowired
    private OverflowDao overflowDao;

    //保存报溢单
    @Override
    public ServiceVO saveOverflowList(OverflowList overflowList, List<OverflowListGoods> overflowListGoodsList) {
        //保存报溢单
        overflowDao.saveOverflowList(overflowList);
        //根据单号查询报溢单
        OverflowList overflowList1 = overflowDao.selectOverflow(overflowList.getOverflowNumber());
        //获取报溢单id
        Integer overflowListId = overflowList1.getOverflowListId();
        //将overflowListId循环插入到overflowListGoodsList
        for (OverflowListGoods overflowListGoods : overflowListGoodsList) {
            overflowListGoods.setOverflowListId(overflowListId);
        }
        //保存报溢商品单
        overflowDao.saveOverflowListGoods(overflowListGoodsList);

        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }
    //查询报溢单
    @Override
    public Map<String, Object> selectOverflowList(String sTime, String eTime) {
        Map<String, Object> map = new HashMap<>();
        List<OverflowList> overflowLists = overflowDao.selectOverflowList(sTime,eTime);
        map.put("rows",overflowLists);
        return map;
    }
    //查询报溢商品
    @Override
    public Map<String, Object> selectOverflowGoodsList(Integer overflowListId) {
        Map<String, Object> map = new HashMap<>();
        List<OverflowListGoods> overflowListGoods = overflowDao.selectOverflowGoodsList(overflowListId);
        map.put("rows",overflowListGoods);
        return map;
    }
}
